<?php
/**
 * @Author: Wang chunsheng  email:2192138785@qq.com
 * @Date:   2020-05-22 17:11:32
 * @Last Modified by:   Wang chunsheng  email:2192138785@qq.com
 * @Last Modified time: 2020-05-24 10:58:44
 */
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev');
defined('WEB_ROOT') or define('WEB_ROOT', dirname(__DIR__).'/web'); //web目录的路径，用户访问的静态文件都放这里

require __DIR__.'/../../vendor/autoload.php';

$config = [
    'id' => 'api-test-hello',
    'setting' => [
        // swoole_server 的配置。
        // @see 其他配置项见 https://wiki.swoole.com/wiki/page/274.html
        'daemonize' => 0,
        'worker_num' => 2,
        'task_worker_num' => 1,
        'log_file' => __DIR__.'/../runtime/logs/swoole.log',
        'log_level' => 0,
        'chroot' => '/',
    ],
    'cacheTable' => function () {
        // swoole_table 需要提前启动，大小为 2 的次方
        return deepziyu\yii\swoole\cache\SwooleCache::initCacheTable(1024);
    },
    'bootstrap' => [
        'class' => 'deepziyu\yii\swoole\bootstrap\YiiWeb',
        'config' => function () {
            // 用闭包是为了延迟加载
            // 返回 Yii 的各个组件的配置
            require_once __DIR__.'/../../vendor/autoload.php';
            require_once __DIR__.'/../../yii-swoole/Yii.php';
            require __DIR__.'/../config/bootstrap.php';

            $config = yii\helpers\ArrayHelper::merge(
                require(__DIR__.'/../config/main.php'),
                require(__DIR__.'/../config/main-local.php'),
                [
                    'components' => [
                      'errorHandler' => [
                           'class' => 'deepziyu\yii\swoole\web\ErrorHandler',
                        ],
                        'cache' => [
                            'class' => 'deepziyu\yii\swoole\cache\SwooleCache',
                        ],
                    ],
                ]
            );

            return $config;
        },
    ],
];
// 配置了这么多，最终还是逃不过一 run()
deepziyu\yii\swoole\server\Server::run($config);
